package com.software_product_construction.backend_software_product_construction.controller;

import com.software_product_construction.backend_software_product_construction.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping(value = "/login")
public class LoginController {

    @Autowired
    LoginService loginService;

    public LoginController() {
    }

    /**
     * 经过测试，没有问题
     * @param loginType
     * @param username
     * @param password
     * @return
     */
    @GetMapping(value = "/Login")
    @ResponseBody
    public boolean canLogin(String loginType, String username, String password){
        return loginService.canLogin(loginType, username, password);
    }

    /**
     * 经过测试，验证验证码没问题
     * @param phone
     * @param code
     * @return
     */
    @GetMapping(value = "/verifyVerificationCode")
    @ResponseBody
    public boolean codeRight(String phone, String code){
        return loginService.codeRight(phone, code);
    }

    /**
     * 经过测试，没有问题
     * @param phone
     * @return
     */
    @GetMapping(value = "/sendVerifyCode")
    @ResponseBody
    public boolean sent(String phone){
        return loginService.sent(phone);
    }

    /**
     * 经过测试，注册租户和用户没有问题
     * @param type
     * @param username
     * @param password
     * @param lesseeId
     * @return
     */
    @GetMapping(value = "/register")
    @ResponseBody
    public boolean register(String type, String username, String password, String lesseeId){
        return loginService.register(type, username, password, lesseeId);
    }

}
